import * as utils from './util.js';
import CONFIG from '../config.js';
const gameListUrl = require('../config').gameListUrl
const tongJiUrl = require('../config').tongJiUrl
const newGameListUrl = require('../config').newGameListUrl
const bannerListUrl = require("../config").bannerListUrl
const noticeMesgUrl = require("../config").noticeMesgUrl
const detailInfoUrl = require('../config').detailInfoUrl
const activityListUrl = require('../config').activityListUrl
const updateUserInfoUrl = require('../config').updateUserInfoUrl
const taskListUrl = require('../config').taskListUrl
const lingquUrl = require('../config').lingquUrl
const recordShareUrl = require('../config').recordShareUrl
const choujiangUrl = require('../config').choujiangUrl
const jiangPinUrl = require('../config').jiangPinUrl
const myPrizeUrl = require('../config').myPrizeUrl
const prizeSubmitUrl = require('../config').prizeSubmitUrl
const myinfoUrl = require('../config').myinfoUrl
const allShopUrl = require('../config').allShopUrl
const submitShopInfo = require('../config').submitShopInfo
const myShopUrl = require('../config').myShopUrl
const quickAddReward = require('../config').quickAddReward
const baseRedPack = require('../config').baseRedPack
const redPackList = require('../config').redPackList
const grabRedPackNew = require('../config').grabRedPackNew
const myRedPack = require('../config').myRedPack
const tixianUrl = require('../config').tixianUrl
const sceneProUrl = require('../config').sceneProUrl
const duobaoList = require('../config').duobaoList
const duobaoDetail = require('../config').duobaoDetail
const joinDBLists = require('../config').joinDBLists
const excTicket = require('../config').excTicket
const joinDB = require('../config').joinDB
const myDBInfo = require('../config').myInfo
const cjRecord = require('../config').cjRecord
const zjRecord = require('../config').zjRecord
const submitAddress = require('../config').submitAddress

const gyMyZhuLi = require('../config').gyMyZhuLi
const gyAllZhuLi = require('../config').gyAllZhuLi
let app = getApp();
// let DOMIAN = CONFIG[CONFIG.WX_ENV];
const getUserId = () => {
  var userInfo = app.globalData.userInfo ? app.globalData.userInfo : app.getUserInfo();
  var user_id = userInfo ? userInfo.UserId : '';
  console.log('getUserId', user_id)
  return user_id;
};
const showToast = (title) => {
  if (title == '') return;
  wx.showToast({
    title: title,
    icon: 'none',
    duration: 2000
  })
}

let S_request = {
  index: {
    getGameList: function(cb, page) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: gameListUrl,
        data: { //请求的参数
          token: token
        },
        success: (res) => {
          let result = res.data;
          page.setData({
            isShowNetWork: false
          })
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          page.setData({
            isShowNetWork: true
          })
          console.log(err)
        }
      })
    },
    tongJiNum: function(id, param, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: tongJiUrl + "?token=" + token + "&id=" + id + "&" + param,
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getNewGameList: function(scene, userId, share, cb, page) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: gameListUrl,
        data: { //请求的参数
          token: token,
          scene: scene,
          fu: userId,
          shareType: share
        },
        success: (res) => {
          let result = res.data;
          page.setData({
            isShowNetWork: false
          })
          // console.log("index res====" + JSON.stringify(res))
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          page.setData({
            isShowNetWork: true
          })
          console.log(err)
        }
      })
    },
    bannerList: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: bannerListUrl,
        data: { //请求的参数
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getNotices: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: noticeMesgUrl,
        data: { //请求的参数
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    updateUserInfo: function(userInfo, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        method: 'POST', //默认是GET
        url: updateUserInfoUrl,
        data: { //请求的参数
          token: token,
          nickname: userInfo.nickName,
          head_icon: userInfo.avatarUrl,
          userinfo: JSON.stringify(userInfo)
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    recordShare: function(gameId, obj, cb) {
      let token = wx.getStorageSync("token");
      obj.token = token
      obj.taskid = 2
      obj.game_id = gameId
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: recordShareUrl,
        data: obj,
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getUserInfo: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: myinfoUrl,
        data: { //请求的参数
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    quickAddReward: function(check, cb) {
      let token = wx.getStorageSync("token");
      console.log("token===" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: quickAddReward,
        data: { //请求的参数
          token: token,
          check: check
        },
        success: (res) => {
          typeof cb == "function" && cb(res.data);
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    enterScenePro: function(scene, cb) {
      let token = wx.getStorageSync("token");
      console.log("token===" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: sceneProUrl,
        data: { //请求的参数
          token: token,
          scene: scene
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    }
  },
  play: {
    getPlayGameList: function(cb, page) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: newGameListUrl,
        data: { //请求的参数
          token: token,
          typeid: 38
        },
        success: (res) => {
          let result = res.data;
          page.setData({
            isShowNetWork: false
          })
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          page.setData({
            isShowNetWork: true
          })
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getDetailInfo: function(id, cb) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: detailInfoUrl,
        data: { //请求的参数
          token: token,
          id: id
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    }
  },
  mine: {
    getActivityList: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: activityListUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getTaskList: function(cb, page) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: taskListUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          page.setData({
            isShowNetWork: false
          })
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          page.setData({
            isShowNetWork: true
          })
          console.log(err)
        }
      })
    },
    lingquReward: function(id, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: lingquUrl,
        data: {
          token: token,
          taskid: id
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
          // console.log(res, data)
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    chouJiang: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: choujiangUrl,
        data: {
          token: token
        },
        success: (res) => {
          typeof cb == "function" && cb(res.data);
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    jiangPin: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: jiangPinUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    myPrizeList: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: myPrizeUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    prizeSubmit: function(id, mobile, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        method: 'POST',
        url: prizeSubmitUrl,
        data: {
          token: token,
          id: id,
          contact_mobile: mobile
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getAllShop: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: allShopUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getMyShop: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: myShopUrl,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    submitShopInfo: function(id, mobile, name, address, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: submitShopInfo,
        data: {
          token: token,
          taskid: id,
          contact_mobile: mobile,
          contact_name: name,
          contact_address: address
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    }
  },
  redPack: {
    getBaseRedPack: function(id, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: baseRedPack,
        data: {
          token: token,
          id: id
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getRedPackList: function(id, page, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: redPackList,
        data: {
          token: token,
          id: id,
          page: page
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    myRedPackInfo: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: myRedPack,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    tixian: function(money, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        method: 'POST',
        url: tixianUrl,
        data: {
          token: token,
          money: money
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            wx.showModal({
              title: '提现失败',
              content: result.msg,
              showCancel: false
            })
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    grabRedPackNew: function(id, timeIng, formId, voiceurl, cb) {
      let token = wx.getStorageSync("token");
      // console.log("success formId===" + formId)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST',
        url: grabRedPackNew,
        data: {
          token: token,
          id: id,
          timeIng: timeIng,
          formId: formId,
          voiceurl: voiceurl
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
            // console.log("result.data==" + JSON.stringify(result.data))
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    }
  },
  duobao: {
    getDuobaoList: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: duobaoList,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getDBDetail: function(id, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: duobaoDetail,
        data: {
          token: token,
          id: id
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getJoinDBList: function(page, id, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: joinDBLists,
        data: {
          token: token,
          id: id,
          page: page
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    joinDB: function(id, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: joinDB,
        data: {
          token: token,
          id: id
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    excTicket: function(num, gold, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: excTicket,
        data: {
          token: token,
          num: num,
          gold: gold
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
            showToast("兑换成功");
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    myDBInfo: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: myDBInfo,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    cjRecord: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: cjRecord,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    zjRecord: function(cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: zjRecord,
        data: {
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    excJP: function(id, contact_mobile, contact_name, contact_address, cb) {
      let token = wx.getStorageSync("token");
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        url: submitAddress,
        data: {
          token: token,
          id: id,
          contact_name: contact_name,
          contact_mobile: contact_mobile,
          contact_address: contact_address
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
  },
  login: function(email, pwd, cb) {
    wx.request({
      header: utils.requestHeader(),
      url: DOMIAN.HOST.API_URL + "/Home/Api/login",
      data: {
        email: email,
        pwd: pwd
      },
      success: (res) => {
        var data = res;
        typeof cb == "function" && cb(data);
        console.log(res, data)
      },
      fail: (err) => {
        console.log('error', err);
        wx.navigateBack();
      }
    })
  },
  gy: {
    getMyZhuli: function(cb) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: gyMyZhuLi,
        data: { //请求的参数
          token: token
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
    getAllZhuli: function(page, cb) {
      let token = wx.getStorageSync("token");
      // console.log("token==" + token)
      wx.request({
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 默认值
        },
        // method: 'POST', //默认是GET
        url: gyAllZhuLi,
        data: { //请求的参数
          token: token,
          page: page
        },
        success: (res) => {
          let result = res.data;
          if (result.code == 0) {
            typeof cb == "function" && cb(result.data);
          } else {
            console.log(result.msg)
            showToast(result.msg);
          }
        },
        fail: (err) => {
          err.statusCode = CONFIG.CODE.REQUESTERROR;
          //  typeof cb == "function" && cb(err);
          console.log(err)
        }
      })
    },
  }
};
module.exports = S_request;